$(document).ready(function(){
	const api = require("../modules/api.js");
	let search = {
		pageNo: 1,
		pageSize: 10
	};
	const order_temp = env.getTemplate("h5/order.html");
	let pageCount = 0;
	let is_loading = true;

	//滚动加载更多
	$(window).scroll(function(e){
		let order_list_height = $(".order-list").height();
		let scrollTop = $(this).scrollTop();
		let screenHeight = $(this).height();
		if((scrollTop + screenHeight > order_list_height) && is_loading ){
			is_loading = false;
			if(search.pageNo < pageCount){
				search.pageNo += 1;
				setTimeout(()=>{
					getList();
				}, 200);

				$(".loading").show();
				$(".ending").hide();
			}else{
				$(".loading").hide();
				$(".ending").show();
			};
		};
	});

	// 获取列表
	getList();
	function getList(){
		api.order_list(search).then(res=>{
			if(res.code == "0"){
				let list = res.result.list || [];
				is_loading = true;
				pageCount = res.result.page.pageCount;
				if(search.pageNo > 1){
					render_order(list);
				};
			};
		});
	};
	// 渲染
	function render_order(list){
		order_temp.render({list, type: "order"}, (err, html)=>{
			$(".order-list").append(html);
		});
	};
});